import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

const router =  new Router({
  routes: [
    {
      path: '/home',
      name: 'home',
	  redirect:'/welcome',
      component:()=>import('../views/Home/index.vue'),
			meta:{
				requireAuth:true
			},
			children:[
				{
				  path: '/welcome',
				  name: 'welcome',
				  component:()=>import('../views/Home/HomeChildren/Welcome/welcome.vue'),
				  meta:{
				  	requireAuth:true
				  }
				},
				// 评论管理
				// 评论列表
				{
				  path: '/评价列表',
				  name: 'CommentList',
				  component:()=>import('../views/Home/HomeChildren/Comment/CommentList.vue'),
				  meta:{
				  	requireAuth:true
				  }
				},
				// 菜单管理
				// 菜单列表
				{
				  path: '/菜单列表',
				  name: 'MenuList',
				  component:()=>import('../views/Home/HomeChildren/MenuManage/MenuList.vue'),
				  meta:{
				  	requireAuth:true
				  }
				},
				// 添加菜单
				{
				  path: '/添加菜单',
				  name: 'AddMenu',
				  component:()=>import('../views/Home/HomeChildren/MenuManage/AddMenu.vue'),
				  meta:{
				  	requireAuth:true
				  }
				},
				// 订单管理
				// 订单列表
				{
				  path: '/订单列表',
				  name: 'OrderList',
				  component:()=>import('../views/Home/HomeChildren/Order/OrderList.vue'),
				  meta:{
				  	requireAuth:true
				  }
				},
				// 商品管理
				// 添加商品
				{
				  path: '/添加商品',
				  name: 'AddShopping',
				  component:()=>import('../views/Home/HomeChildren/ShoppingManage/AddShopping.vue'),
				  meta:{
				  	requireAuth:true
				  }
				},
				// 商品列表
				{
				  path: '/商品列表',
				  name: 'ShoppingList',
				  component:()=>import('../views/Home/HomeChildren/ShoppingManage/ShoppingList.vue'),
				  meta:{
				  	requireAuth:true
				  }
				},
				// 分类管理
				// 添加分类
				{
				  path: '/添加分类',
				  name: 'AddSort',
				  component:()=>import('../views/Home/HomeChildren/Sort/AddSort.vue'),
				  meta:{
				  	requireAuth:true
				  }
				},
				// 分类列表
				{
				  path: '/分类列表',
				  name: 'SortList',
				  component:()=>import('../views/Home/HomeChildren/Sort/SortList.vue'),
				  meta:{
				  	requireAuth:true
				  }
				  
				},
				// 轮播图管理
				// 添加轮播图
				{
				  path: '/添加轮播',
				  name: 'AddSwipe',
				  component:()=>import('../views/Home/HomeChildren/SwipeManage/AddSwipe.vue'),
				  meta:{
				  	requireAuth:true
				  }
				},
				// 轮播图列表
				{
				  path: '/轮播列表',
				  name: 'SwipeList',
				  component:()=>import('../views/Home/HomeChildren/SwipeManage/SwipeList.vue'),
				  meta:{
				  	requireAuth:true
				  }
				},
				// 用户管理
				// 用户列表
				{
				  path: '/用户列表',
				  name: 'UserList',
				  component:()=>import('../views/Home/HomeChildren/User/UserList.vue'),
				  meta:{
				  	requireAuth:true
				  }
				},
			]
    },
		{
		  path: '/login',
		  name: 'login',
		  component:()=>import('../views/Login/index.vue')
		},
		{
		  path: '/',
		  redirect: {name:'login'}
		}
  ]
  
})
// 路由守卫	
router.beforeEach((to,from,next)=>{
	if(to.meta.requireAuth){
		const token=sessionStorage.getItem('token')
		if(!token){
			next('/login')
		}else{
			next()
		}
	}else{
		next()
	}
})









export default router;

